package com.xty.xtyle.utils;

import android.widget.Toast;

import com.xty.xtyle.MyApp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CommonUtil {

    //统一显示toast信息
    public static void showToast( String msg) {
        Toast.makeText(MyApp.getContext(), msg, Toast.LENGTH_SHORT).show();
    }

    public static String passDateStr(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// hh:mm:ss")
        return format.format(date);
    }

    /**
     * 将文字格式时间,转换为date格式
     * @param date
     * @return
     */
    public static Date passDate2Date(String date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// hh:mm:ss")
        try {
            return format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static Long passDate2Long(String date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// hh:mm:ss")
        try {
            return format.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0L;
    }
}
